//
//  PSMoveTests.m
//  PrefCore
//
//  Created by Sergey on 5/13/14.
//  Copyright (c) 2014 Play-on-smart. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "PSMove.h"
#import "PSNode.h"

@interface PSMoveTests : XCTestCase

@end

@implementation PSMoveTests

- (void)testCreate {
    PSTreeLevel *lvl = [[PSTreeLevel alloc] initWithRound:123];
    PSNode *node = [PSNode nodeWithLevel:lvl starter:0 hand0:1 hand1:2 hand2:4];
    PSCard *c0 = [PSCard cardWithIndex:1];
    PSCard *c1 = [PSCard cardWithIndex:2];
    PSCard *c2 = [PSCard cardWithIndex:3];
    PSMove *move = [PSMove moveWithCard0:c0 card1:c1 card2:c2 andNode:node];
    XCTAssertNotNil(move);
    XCTAssertEqual(c0.compressed, move.c0);
    XCTAssertEqual(c1.compressed, move.c1);
    XCTAssertEqual(c2.compressed, move.c2);
    XCTAssertEqual(node, move.node);
    [move destroyWithRecycle:YES];
}

-(void)testCardForPlayer {
    PSTreeLevel *lvl = [[PSTreeLevel alloc] initWithRound:123];
    PSNode *node = [PSNode nodeWithLevel:lvl starter:0 hand0:1 hand1:2 hand2:4];
    PSCard *c0 = [PSCard cardWithIndex:1];
    PSCard *c1 = [PSCard cardWithIndex:2];
    PSCard *c2 = [PSCard cardWithIndex:3];
    PSMove *move = [PSMove moveWithCard0:c0 card1:c1 card2:c2 andNode:node];
    XCTAssertEqual(c0.compressed, [move cardForPlayerId:0]);
    XCTAssertEqual(c1.compressed, [move cardForPlayerId:1]);
    XCTAssertEqual(c2.compressed, [move cardForPlayerId:2]);
    [move destroyWithRecycle:YES];
    NSLog(@"Node: %@", [PSNode pool]);
    NSLog(@"Move: %@", [PSMove pool]);
}

-(void)testDestroyWithRecycle {
    PSObjectPool *pool = [PSMove pool];
    [pool setCapacity:10000];
    XCTAssertEqualObjects(@"Pool: 10000/0, total=10000", [pool description]);
    PSTreeLevel *lvl = [[PSTreeLevel alloc] initWithRound:123];
    PSNode *node = [PSNode nodeWithLevel:lvl starter:0 hand0:1 hand1:2 hand2:4];
    PSCard *c0 = [PSCard cardWithIndex:1];
    PSCard *c1 = [PSCard cardWithIndex:2];
    PSCard *c2 = [PSCard cardWithIndex:3];
    PSMove *move = [PSMove moveWithCard0:c0 card1:c1 card2:c2 andNode:node];
    XCTAssertEqualObjects(@"Pool: 9999/1, total=10000", [pool description]);
    [move destroyWithRecycle:YES];
    XCTAssertEqualObjects(@"Pool: 10000/0, total=10000", [pool description]);
}

-(void)testDescription {
    PSTreeLevel *lvl = [[PSTreeLevel alloc] initWithRound:123];
    PSNode *node = [PSNode nodeWithLevel:lvl starter:0 hand0:1 hand1:2 hand2:4];
    PSCard *c0 = [PSCard cardWithIndex:1];
    PSCard *c1 = [PSCard cardWithIndex:2];
    PSCard *c2 = [PSCard cardWithIndex:3];
    PSMove *move = [PSMove moveWithCard0:c0 card1:c1 card2:c2 andNode:node];
    XCTAssertEqualObjects(@"♠7 ♠8 ♠9", [move description]);
    [move destroyWithRecycle:YES];
}

@end
